//CSC330_Alex_Stoyko_Lab4
#include "DeckofCards.h"
#include "Card.h"
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

DeckofCards::DeckofCards() //default constructor
{
	cards.clear();  //clear the vector
	currentCard = 0;  //current card set to 0
	
    for (int s = 0; s < 4; s++)  //create 52 cards and add to the vector
        for (int v = 1; v <= 13; v++)
            cards.push_back(Card(s, v));  //to put each next card to the end of vector
}

void DeckofCards::shuffle()
{
    //srand(time(0)); // random number generator function
	srand ( (unsigned int)time(NULL) );
    for (int i = 0; i < 52; i++)
    {
        int n1 = rand() % cards.size(); //generates number from 1 t0 52
        
		//swap 2 cards at n1 and n2 index
        Card temp = cards[n1];
        cards[n1] = cards[i];
        cards[i] = temp;
    }
}

Card DeckofCards::dealCard()
{
	Card card = cards.at(currentCard);  //The at() function checks that the index if within the bounds, if it's not it will throw an exception
	        currentCard++;
	        return card;
}

bool DeckofCards::moreCards()
{
	return currentCard < 52;  //current card < 52
}

